<!--
 * @Author: hq
 * @Date: 2022-05-18 19:57:54
 * @LastEditors: hq
 * @LastEditTime: 2022-07-01 15:03:07
 * @Description: your project
 * @version: 1.0
-->
<template>
  <div class="shouye">
    <div class="card">
      <div class="col">
        <i class="el-icon-shopping-cart-full i1"></i>
        <div class="ti">
          <div class="num">上架商品</div>
          <div class="number">{{ product_nums }}</div>
        </div>
      </div>
      <div class="col">
        <i class="el-icon-coin i2"></i>
        <div class="ti">
          <div class="num">
            销售额
            <div class="day2">今日</div>
          </div>
          <div class="number">{{ cash_sale }}</div>
        </div>
      </div>
      <div class="col">
        <i class="el-icon-coin i2"></i>
        <div class="ti">
          <div class="num">赠送积分额度</div>
          <div class="number">{{ recharge_integral }}</div>
        </div>
      </div>
      <div class="col">
        <i class="el-icon-s-order i3"></i>
        <div class="ti">
          <div class="num">
            订单量
            <div class="day3">今日</div>
          </div>
          <div class="number">{{ order_nums }}</div>
        </div>
      </div>
      <div class="col">
        <i class="el-icon-star-on i4"></i>
        <div class="ti">
          <div class="num">收藏量</div>
          <div class="number">{{ collect_nums }}</div>
        </div>
      </div>
    </div>

    <div class="card_con">
      <div class="title">订单量趋势</div>
      <div v-if="notData">
        <div class="echart" id="mychart" :style="myChartStyle"></div>
      </div>
      <div class="zwsj" v-else>
        <img src="@/assets/zwsj.png" alt="" />
        <div class="null">暂无数据 ~</div>
      </div>
    </div>
  </div>
</template>

<script>
import { saleData } from "@/api/merchant";
import * as echarts from "echarts";
export default {
  data() {
    return {
      xData: [], //横坐标
      yData: [], //数据
      myChartStyle: { float: "left", width: "100%", height: "400px" }, //图表样式
      product_nums: "",
      cash_sale: "",
      recharge_integral: "",
      order_nums: "",
      collect_nums: "",
      notData: false,
    };
  },
  mounted() {
    this.saleData();
  },
  methods: {
    async saleData() {
      const { data, err } = await saleData({});
      //   (data);
      if (err === 0) {
        this.notData = true;
        this.xData = data.date;
        this.yData = data.data;
        this.product_nums = data.product_nums;
        this.cash_sale = data.cash_sale;
        this.recharge_integral = data.recharge_integral;
        this.order_nums = data.order_nums;
        this.collect_nums = data.collect_nums;
        if (data.date.length === 0 || data.data.length === 0) {
          this.notData = false;
        } else {
          console.log(data);

          this.$nextTick(() => {
            this.initEcharts();
          });
        }
      }
    },
    initEcharts() {
      // 基本柱状图
      const option = {
        tooltip: {
          trigger: "axis",
        },
        xAxis: {
          type: "category",
          data: this.xData,
        },
        yAxis: {
          type: "value",
        },
        series: [
          {
            data: this.yData,
            type: "line",
          },
        ],
      };
      const myChart = echarts.init(document.getElementById("mychart"));
      myChart.setOption(option);
      //随着屏幕大小调节图表
      window.addEventListener("resize", () => {
        myChart.resize();
      });
    },
  },
  created() {},
};
</script>

<style lang="scss" scoped>
.shouye {
  .card {
    display: flex;
    margin-bottom: 20px;
    justify-content: space-between;
    .col {
      display: flex;
      border-radius: 4px;
      width: 19%;
      background-color: #fff;
      padding: 30px;
      box-sizing: border-box;
      i {
        flex-shrink: 0;
        font-size: 40px;
      }
      .ti {
        margin-left: 30px;
        width: 100%;
        .num {
          width: 100%;
          color: #999999;
          font-weight: bold;
          font-size: 16px;
          margin-bottom: 15px;
          display: flex;
          align-items: center;
          justify-content: space-between;
          div {
            font-size: 12px;
            font-weight: 400;
          }
        }
        .number {
          font-size: 30px;
        }
      }
      .i1 {
        color: rgb(255, 156, 110);
      }
      .i2 {
        color: rgb(149, 222, 100);
      }
      .i3 {
        color: rgb(179, 127, 235);
      }
      .i4 {
        font-size: 50px;
        color: rgb(255, 214, 102);
      }

      .day3 {
        color: rgb(179, 127, 235);
        border: 1px solid rgb(179, 127, 235);
        border-radius: 4px;
        padding: 0 4px;
        box-sizing: border-box;
      }
      .day2 {
        color: rgb(149, 222, 100);
        border: 1px solid rgb(149, 222, 100);
        border-radius: 4px;
        padding: 0 4px;
        box-sizing: border-box;
      }
    }
  }
  .echart {
    background-color: #fff;
  }
  .card_con {
    height: calc(100vh - 150px);
    .title {
      font-size: 20px;
      font-weight: bold;
    }
    .zwsj {
      text-align: center;
      img {
        width: 240px;
        height: 240px;
      }
      .null {
        text-align: center;
      }
    }
  }
}
</style>
